package com.yhb.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yhb.channel.model.IUserInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.edzh.spring.bootstrap.model.IUser;

import java.util.Date;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class User implements IUser, IUserInfo {

    public final static String ADMIN = "ADMIN";
    public final static String USER = "USER";

    public final static int A_ADMIN = 10;
    public final static int A_USER = 0;

    public enum VipType {
        ORDINARY, // 没付过钱
        PAYED, // 交了钱的
        PRIME // 皇冠
    }

    public enum VipSubType {
        TEMP, // 试用, 奖励等发放用
        PERMANENT // 永久
    }

    private String id;
    private String mobile;
    private String character;
    private VipType vipType;

    private VipSubType vipSubType; // vip子类型 (beggar 等放这里)


    @JsonIgnore
    private Date vipStartTime; // 对试用vip 需要校验这两个字段

    @JsonIgnore
    private Date vipValidation; // 对试用vip 需要校验这两个字段

    private Integer purchasedVipLevel; // 代理商最低 vip 等级 分润计算阶段用


    private Date primeVipValidation; // 皇冠vip到期时间, 普通vip没有过期
    private String nickname;
    private String inviteCode;
    private Integer certificated;
    private String gender;

    private Certificate certificate;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String password;
    private String avatar;

    @JsonIgnore
    public String getDashFreeUserId() {
        return getId().replace("-", "");
    }

    private Date registerTime;

    @JsonIgnore
    @Override
    public int getAuthPrivileges() {
        switch (getCharacter()) {

            case USER:
            default:
                return A_USER;

        }
    }

    @JsonIgnore
    @Override
    public String getUserPhone() {
        return getMobile();
    }

    @JsonIgnore
    @Override
    public String getEmail() {
        return "a@b.com";
    }

    @Override
    @JsonIgnore
    public String getStringVipType() {
        return getVipType().toString();
    }

    @JsonIgnore
    public boolean isModifiableVipType() {
        return vipType == VipType.ORDINARY || vipSubType == VipSubType.TEMP; // 临时vip 或者普通会员都可以升级
    }

    @JsonIgnore
    public void updateToPermanentVip() {
        if (vipType != VipType.PRIME) {
            vipType = VipType.PAYED;
            vipSubType = VipSubType.PERMANENT;
        }
    }

    @JsonIgnore
    public boolean isTempVip() {
        return vipType == VipType.PAYED && vipSubType == VipSubType.TEMP;

    }
}
